﻿using System;
using System.Data;
using System.Collections.Generic;

using Clipper.Model;
using System.Collections.ObjectModel;
using Global;
namespace Clipper.BLL
{
	/// <summary>
	/// SystemConfig
	/// </summary>
	public partial class SystemConfig
	{
		private readonly Clipper.DAL.SystemConfig dal=new Clipper.DAL.SystemConfig();
		public SystemConfig()
		{}
		#region  BasicMethod
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string parameterName)
		{
			return dal.Exists(parameterName);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Clipper.Model.SystemConfig model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Clipper.Model.SystemConfig model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string parameterName)
		{
			
			return dal.Delete(parameterName);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string parameterNamelist )
		{
			return dal.DeleteList(parameterNamelist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Clipper.Model.SystemConfig GetModel(string parameterName)
		{
			
			return dal.GetModel(parameterName);
		}

		

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public ObservableCollection<Clipper.Model.SystemConfig> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public ObservableCollection<Clipper.Model.SystemConfig> DataTableToList(DataTable dt)
		{
			ObservableCollection<Clipper.Model.SystemConfig> modelList = new ObservableCollection<Clipper.Model.SystemConfig>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Clipper.Model.SystemConfig model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
					}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  BasicMethod
		#region  ExtensionMethod
        /// <summary>
        /// 加载配置信息
        /// </summary>
        public void LoadConfig()
        {
            ServiceProvider.ConfigVM.AdminPwd = dal.GetModel("AdminPwd").value;

        }
        /// <summary>
        /// 验证管理员密码
        /// </summary>
        /// <param name="pwd">输入的密码</param>
        /// <returns>验证是否通过</returns>
        public bool CheckAdminPwd(string pwd)
        {
            bool res = false ;
            if (ServiceProvider.ConfigVM.AdminPwd == Functions.EncryptDES(pwd))
            {
                res = true;
                ServiceProvider.AdminValidate = true;
            }
            return res;
        }
        /// <summary>
        /// 验证工程师的天密码
        /// </summary>
        /// <param name="pwd">输入的密码</param>
        /// <returns>验证是否通过</returns>
        public bool CheckDatePwd(string pwd)
        {
            bool res = false;
            string engineerPwd = Functions.EncryptDES(DateTime.Now.ToString("yyyyMMdd"));
            if (engineerPwd == pwd)
            {
                res = true;
                ServiceProvider.EngineerValidate = true;
            }
            return res;
        }
		#endregion  ExtensionMethod
	}
}

